﻿
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>金茂智慧小区系统项目</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="~/layui/css/layui.css" rel="stylesheet" />
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="~/layui/jquery-3.3.1.js"></script>
    <script src="~/layui/layui.js"></script>
    <script src="~/layui/vue.min.js"></script>
</head>
<body>
    <form class="layui-form" lay-filter="example">
        <div class="layui-form-item">
            <label class="layui-form-label">模式</label>
            <div class="layui-input-block">
                <input id="mode" type="checkbox" name="close" lay-filter="switchTest" lay-skin="switch" lay-text="授权|普通">
            </div>
        </div>
    </form>
    <span class="layui-breadcrumb" lay-separator="|">
        <a href="/ViewCardInfo/Index">业主信息</a>
        <a id="floorBtn" style="cursor:pointer;">楼层设置</a>
        <a href="/ViewFloorParameter/Index">设备信息</a>
        <a href="/ViewFloorParameter/DeviceIndex">状态查询</a>
        <a id="btnReboot">重启</a>
    </span>
    <script>
        window.onload = function () {
            var defaultMode = 1;
            $.ajax({
                url: '/api/Authorize/QueryMode',
                type: 'POST',
                async: false,
                dataType: 'json',
                success: function (res) {
                    if (res.errcode !== 0) return layer.alert(res.errmsg);
                    defaultMode = res.data.workmode;
                    console.log(res);
                }
            })
            layui.use(['form'], function () {
                var form = layui.form;
                //监听指定开关
                form.on('switch(switchTest)', function (data) {
                    var mode = 1;
                    if (this.checked) {
                        // 授权模式
                        mode = 0;
                    }
                    $.ajax({
                        url: '/api/Authorize/SwitchingMode?devid=1&mode=' + mode,
                        type: 'POST',
                        dataType: 'json',
                        success: function (res) {
                            if (res.errcode !== 0) return layer.alert(res.errmsg);
                            layer.msg('切换成功')
                        }
                    })

                });
                form.val("example", {
                    "close": defaultMode === 0 ? true : false
                });
                form.render();
            });
            $("#floorBtn").click(function () {
                layer.prompt({
                    formType: 1,
                    title: '请输入登录密码'
                }, function (val, index) {
                    // 调用登录接口Login
                    $.ajax({
                        url: '/api/ElevatorInfo/Login?pwd=' + val,
                        type: 'POST',
                        dataType: 'json',
                        success: function (res) {
                            if (res.errcode !== 0) return layer.msg(res.errmsg);
                            layer.msg('登录成功');
                            layer.open({
                                type: 2,
                                title: '楼层列表',
                                shadeClose: true,
                                shade: false,
                                //maxmin: true, //开启最大化最小化按钮
                                area: ['893px', '600px'],
                                content: '/ViewElevatorInfo/index'
                            });
                            //window.location.href = '';
                        }
                    })
                });
            })
            $("#btnReboot").click(function () {
                $.ajax({
                    url: '/api/Device/Reboot',
                    type: 'POST',
                    dataType: 'json',
                    success: function (res) {
                        if (res.errcode !== 0) return layer.msg(res.errmsg);
                        layer.msg('重启成功');
                    }
                })                    
            })
        }

    </script>

</body>
</html>